﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace dataset
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string connstrng = "Data Source=.;Initial Catalog=StudentCourse;Integrated Security=True";
            SqlConnection connection = new SqlConnection(connstrng);
            connection.Open();
            string sqlstring = "select Sno,Sname from Student";
            SqlCommand mycommand = new SqlCommand(sqlstring,connection);
            SqlDataAdapter adapter = new SqlDataAdapter();
            adapter.SelectCommand = mycommand;
            DataSet sqlds = new DataSet();
            adapter.Fill(sqlds);
            string var = "";
            for (int i = 0; i < sqlds.Tables[0].Rows.Count; i++)
            { 
                var += sqlds.Tables[0].Rows[i][ "Sno"].ToString() +sqlds.Tables[0].Rows[i][ "Sname"].ToString() +"\n";
            }
            MessageBox.Show(var);
            connection.Dispose();
            connection.Close();
            connection=null;
        }
    }
}
